package com.lin.filegraph.utils.parser.node;

import org.eclipse.jdt.core.dom.ASTNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 10:21
 */

public abstract class JTypeNode extends JTreeNode {
    private String typeName = null;// ������
    private String modifier = null;// ���͵����η�
    private String strOuterType;// �ⲿ����
    //	private List<TypeNode> listInnerType = new ArrayList<TypeNode>();// ��������������ڲ���
    private List<String> listStrSuperInterface = new ArrayList<String>(); // ����Class���Enum�࣬��ʾʵ�ֵĽӿ��б�����Interface��ʾ���ӿ��б��ӿڿ����Ƿ��Զ���ӿ�
    //	private List<InterfaceNode> listSuperInterface = new ArrayList<InterfaceNode>();// ����Class���Enum�࣬��ʾʵ�ֵĽӿ��б�����Interface��ʾ���ӿ��б��ӿڱ������Զ���ӿ�
    public boolean isGeneric = false;// �ж��Ƿ��Ƿ�������

    public JTypeNode(String filePath, ASTNode astNode, String typeName, String modifier, String strOuterType, List<String> listStrSuperInterface) {
        super(filePath, astNode);
        this.typeName = typeName;
        this.modifier = modifier;
        this.strOuterType = strOuterType;
        this.listStrSuperInterface = listStrSuperInterface;
    }

    public String getTypeName() {
        return typeName;
    }

    public String getModifier() {
        return modifier;
    }

    public List<String> getListStrSuperInterface() {
        return listStrSuperInterface;
    }


    public void addStrSuperInterface(String strSuperInterface) {
        listStrSuperInterface.add(strSuperInterface);
    }

    public String getStrOuterType() {
        return strOuterType;
    }

    public List<JMethodNode> getAllMethods() {
        List<JMethodNode> methodNodeList = new ArrayList<>();
        List<? extends JTreeNode> tempList = super.getChildrenNodeList();
        for (JTreeNode basedNode : tempList) {
            if (basedNode instanceof JMethodNode) {
                JMethodNode MethodNode = (JMethodNode) basedNode;
                methodNodeList.add(MethodNode);
            }
        }
        return methodNodeList;
    }

    public List<JFieldNode> getAllFields() {
        List<JFieldNode> fieldNodeList = new ArrayList<>();
        List<? extends JTreeNode> tempList = super.getChildrenNodeList();
        for (JTreeNode basedNode : tempList) {
            if (basedNode instanceof JFieldNode) {
                JFieldNode FiledNode = (JFieldNode) basedNode;
                fieldNodeList.add(FiledNode);
            }
        }
        return fieldNodeList;
    }

    public JFileNode getFile() {
        JTreeNode fatherNode = super.getFatherNode();
        if (fatherNode instanceof JFileNode) {
            return (JFileNode) fatherNode;
        } else {
            System.err.println("ERR");
            return null;
        }
    }

    public abstract void displayStrInheritance();
}

